﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MVC3DEMO.Models;
namespace MVC3DEMO.Models.BS
{
    public class BS_Menu
    {
        private SQLHeperDataContext sqlheper;
        
    #region Constructor
        public BS_Menu()
        {
            sqlheper = new SQLHeperDataContext();
        }
    #endregion constructor
        public List<Menu> getListMenu()
        {

            return (from c in sqlheper.Menus orderby c.priority ascending select c).ToList();
          
        }

        public Menu getByMenuId(int id)
        {
            return (from c in sqlheper.Menus where c.Id == id select c).FirstOrDefault();
        }
        public int DeleteMenu(Menu menu)
        {
            int result = 0;
            var menus = (from c in sqlheper.Menus where c.Id == menu.Id select c).FirstOrDefault();
            sqlheper.Menus.DeleteOnSubmit(menus);
            sqlheper.SubmitChanges();
            result = 1;
            return result;
        }

        public List<MenuItem> getListMenuItemByIdMenu(int id)
        {
            return (from c in sqlheper.MenuItems where c.MenuId == id select c).ToList(); 
        }
    }
}